<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("buttons.inc.php");
use_unit("checklst.inc.php");
use_unit("components4phpfull/jtscrollbox.inc.php");
use_unit("components4phpfull/jttable.inc.php");
use_unit("components4phpfull/jtlookuplistbox.inc.php");
use_unit("components4phpfull/jtgroupbox.inc.php");
use_unit("components4phpfull/jtiframe.inc.php");
use_unit("platinumgrid/jtplatinumgrid.inc.php");
use_unit("components4phpfull/jtpagecontrol.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class Vehicle_Lookup_Lists extends Page
{
       public $btnDelete = null;
       public $lblStandard = null;
       public $hiddenValueId = null;
       public $edValue = null;
       public $btnUpdate = null;
       public $btnCancel = null;
       public $btnAdd = null;
       public $lblTextValue = null;
       public $hiddenCategory = null;
       public $hiddenTable = null;
       public $JTValues = null;
       public $JTDroplists = null;
       public $JTSiteTheme1 = null;

       function btnDeleteClick($sender, $params)
       {
       $id = $this->hiddenValueId->getValue();
       $table = $this->hiddenTable->getValue();
       $category = $this->hiddenCategory->getValue();

       $query_delete = "DELETE FROM ".$table." WHERE id='".$id."'";
       mysql_query($query_delete) or die(mysql_error());
       redirect('standard_droplist.php?save_to='.$table.'&category='.$category);

       }

       function btnCancelClick($sender, $params)
       {
       redirect('vehicle_list.php');

       }

       function btnUpdateClick($sender, $params)
       {
       $id = $this->hiddenValueId->getValue();
       $table = $this->hiddenTable->getValue();
       $category = $this->hiddenCategory->getValue();

       $query_update = "UPDATE ".$table." SET
       value = '".$this->edValue->getText()."'
       WHERE id='".$id."'";
       mysql_query($query_update) or die(mysql_error());
       redirect('standard_droplist.php?save_to='.$table.'&category='.$category);
       }

       function btnAddClick($sender, $params)
       {
       $id = $this->hiddenValueId->getValue();
       $table = $this->hiddenTable->getValue();
       $category = $this->hiddenCategory->getValue();
       $result_values = mysql_query("INSERT INTO ".$table."(id, value,category) VALUES (
       '".$this->hiddenValueId->getValue()."',
       '".$this->edValue->getText()."',
       '".$category."'
       )")or die("INSERT VALUE - " . mysql_error());
       redirect('standard_droplist.php?save_to='.$table.'&category='.$category.'&id='.$id);
       }

       function Vehicle_Lookup_ListsCreate($sender, $params)
       {
       $table = null;
       $category = null;
       $id = null;
       $this->hiddenValueId->setValue($_GET['id']);
       $this->hiddenTable->setValue($_GET['save_to']);
       $this->hiddenCategory->setValue($_GET['category']);
       $table = $this->hiddenTable->getValue();
       $category = $this->hiddenCategory->getValue();

       $fields_array = array('Expense Accounts', 'Expense Descriptions', 'Expense Types',
       'Fuel Brands', 'Fuel Dealer Names', 'Fuel Octane/Types',
       'Fuel State/Province', 'Inventory Adj Reasons', 'Inventory Manufacturers',
       'Inventory Storeroom/Locations', 'Inventory Types', 'Inventory Unit of Measure',
       'Job Payment Types', 'Parts Descriptions', 'Parts Non-Stock Part Nos',
       'Parts Vendors', 'Personnel Departments', 'Personnel Driving History Types',
       'Personnel Job Grades', 'Personnel Job Titles', 'Personnel Renewals/Certifications',
       'Personnel Training/Certification Types', 'Personnel Work Locations', 'Template Types',
       'Tire Locations', 'Tire Manufacturers', 'Tire Sizes',
       'Tire Types', 'Tire Services Types', 'Tire Wheel Sizes',
       'Vehicle Body Styles', 'Vehicle Manufacturers', 'Vehicle Ownership',
       'Vehicle Journal Categories', 'Work Order Descriptions', 'Work Order Serviced By',
       'Work Order Task Descriptions', 'Work Order Type');

       $category_array = array('accounts', 'descriptions', 'types',
       'brands', 'dealer names', 'octane/Types',
       'state/province', 'adj reasons', 'manufacturers',
       'storeroom/locations', 'types', 'unit of measure',
       'payment types', 'descriptions', 'non-stock part nos',
       'vendors', 'departments', 'driving history types',
       'job grades', 'job titles', 'renewals/certifications',
       'training/certification types', 'work locations', 'types',
       'locations', 'manufacturers', 'sizes',
       'types', 'services types', 'wheel sizes',
       'body styles', 'manufacturers', 'ownership',
       'journal categories', 'descriptions', 'serviced by',
       'task descriptions', 'type');

       $tbl_array = array('lookup_expense_tbl', 'lookup_expense_tbl', 'lookup_expense_tbl',
       'lookup_fuel_tbl', 'lookup_fuel_tbl', 'lookup_fuel_tbl',
       'lookup_fuel_tbl', 'lookup_inventory_tbl', 'lookup_inventory_tbl',
       'lookup_inventory_tbl', 'lookup_inventory_tbl', 'lookup_inventory_tbl',
       'lookup_job_tbl', 'lookup_parts_tbl', 'lookup_parts_tbl',
       'lookup_parts_tbl', 'lookup_personnel_tbl', 'lookup_personnel_tbl',
       'lookup_personnel_tbl', 'lookup_personnel_tbl', 'lookup_personnel_tbl',
       'lookup_personnel_tbl', 'lookup_personnel_tbl', 'lookup_template_tbl',
       'lookup_tire_tbl', 'lookup_tire_tbl', 'lookup_tire_tbl',
       'lookup_tire_tbl', 'lookup_tire_tbl', 'lookup_tire_tbl',
       'lookup_vehicle_tbl', 'lookup_vehicle_tbl', 'lookup_vehicle_tbl',
       'lookup_vehicle_tbl', 'lookup_workorder_tbl', 'lookup_workorder_tbl',
       'lookup_workorder_tbl', 'lookup_workorder_tbl');

       $arr = array();
       $ctr = 0;
       $count = count($fields_array);
       while($ctr<=$count)
       {
        $tools = "<a href='veh_lookup_list.php?save_to=".$tbl_array[$ctr]."&category=".$category_array[$ctr]."'>".$fields_array[$ctr]."</a>";
        $arr[] = array('Drop list Fields ' => $tools);
        $ctr++;
       }
       $this->JTDroplists->setCellData($arr);

       if($table!=null)
       {
       $ctr = 0;
       $arr2 = array();
       $query2 = "SELECT * FROM ".$table." WHERE category='".$category."'";
       //var_dump($query2);
       $result_values = mysql_query($query2);
       while($row_values = mysql_fetch_array($result_values))
       {
        $id = $row_values['id'];
        $value = "<a href='veh_lookup_list.php?save_to=".$table."&id=".$id."&category=".$category."'>".$row_values['value']."</a>";
        $arr2[] = array('Values'=>$value);
        $ctr++;

       $query_select_value = "SELECT * FROM  ".$table." WHERE id='".$this->hiddenValueId->getValue()."'";
       $result_select_value = mysql_query($query_select_value) or die(mysql_error());
       $row_select_value = mysql_fetch_array($result_select_value);
       $this->edValue->setText($row_select_value['value']);
       }
       $this->JTValues->setCellData($arr2);
       }
       }




}

global $application;

global $Vehicle_Lookup_Lists;

//Creates the form
$Vehicle_Lookup_Lists=new Vehicle_Lookup_Lists($application);

//Read from resource file
$Vehicle_Lookup_Lists->loadResource(__FILE__);

//Shows the form
$Vehicle_Lookup_Lists->show();

?>